﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ScaffoldIt.Configuration;

namespace ScaffoldIt
{
    public partial class FormEditTemplateParameter : Form
    {
        public FormEditTemplateParameter()
        {
            InitializeComponent();
        }

        public static bool EditParameter(Parameter parameter)
        {
            using (var frm = new FormEditTemplateParameter())
            {
                frm.Init(parameter);
                frm.textBoxValue.Focus();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    frm.Read(parameter);
                    return true;
                }
            }

            return false;
        }

        private void Read(Parameter parameter)
        {
            parameter.Value = textBoxValue.Text;            
        }

        private void Init(Parameter parameter)
        {
            textBoxCode.Text = parameter.Code;
            textBoxType.Text = parameter.Type;
            textBoxValue.Text = parameter.Value;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
                DialogResult = DialogResult.OK;
        }
    }
}
